package com.boby.homecamera.config

import com.boby.lib_common.BaseApplication
import com.boby.lib_common.util.SharedPrefUtil
import com.boby.lib_common.util.did.DeviceId

object AppConfig {
    private const val  APP_CONFIG_NAME = "AppConfig"

     val did :String  by lazy{ DeviceId.getLocalDevicesId(BaseApplication.instance()) }

    var deviceModel : Int =  -1//是否是服务端模式 0:未选择，1：服务端模式 2：客户端模式
        set(value) {
            field = value
            SharedPrefUtil.putPreference("deviceModel", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field == -1) {
                field = SharedPrefUtil.findPreference("deviceModel", 0, APP_CONFIG_NAME)
            }
            return field
        }

    var userName = ""
        set(value) {
            field = value
            SharedPrefUtil.putPreference("userName", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field.isEmpty()) {
                field = SharedPrefUtil.findPreference("userName", "", APP_CONFIG_NAME)
            }
            return field
        }

    var tokenTime : Int =  -1//token 失效时间 天
    set(value) {
        field = value
        SharedPrefUtil.putPreference("tokenTime", value, APP_CONFIG_NAME,true)
    }
        get() {
            if (field == -1) {
                field = SharedPrefUtil.findPreference("tokenTime", 1, APP_CONFIG_NAME)
            }
            return field
        }
    var detectOrientation : Int =  -1//token 检测方向
    set(value) {
        field = value
        SharedPrefUtil.putPreference("tokenTime", value, APP_CONFIG_NAME,true)
    }
        get() {
            if (field == -1) {
                field = SharedPrefUtil.findPreference("tokenTime", 0, APP_CONFIG_NAME)
            }
            return field
        }

    var videoResolution : Int =  -1//视频分辨率 540，720，1080
    set(value) {
        field = value
        SharedPrefUtil.putPreference("videoResolution", value, APP_CONFIG_NAME,true)
    }
        get() {
            if (field == -1) {
                field = SharedPrefUtil.findPreference("videoResolution", 720, APP_CONFIG_NAME)
            }
            return field
        }

    var videoBitrate : Int =  -1//视频分辨率 1,2
    set(value) {
        field = value
        SharedPrefUtil.putPreference("videoBitrate", value, APP_CONFIG_NAME,true)
    }
        get() {
            if (field == -1) {
                field = SharedPrefUtil.findPreference("videoBitrate", 1, APP_CONFIG_NAME)
            }
            return field
        }

    var isDetectAudioEvent: Boolean? = null // 是否检测音频事件
        set(value) {
            field = value
            SharedPrefUtil.putPreference("isDetectAudioEvent", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field == null) {
                field = SharedPrefUtil.findPreference("isDetectAudioEvent", false, APP_CONFIG_NAME)
            }
            return field
        }
    var isDetectPersonEvent: Boolean? = null // 是否检测音频事件
        set(value) {
            field = value
            SharedPrefUtil.putPreference("isDetectPersonEvent", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field == null) {
                field = SharedPrefUtil.findPreference("isDetectPersonEvent", false, APP_CONFIG_NAME)
            }
            return field
        }
    var videoCameraId : Int =  -1//摄像头 0:后摄，1：前摄
    set(value) {
        field = value
        SharedPrefUtil.putPreference("videoCameraId", value, APP_CONFIG_NAME,true)
    }
        get() {
            if (field == -1) {
                field = SharedPrefUtil.findPreference("videoCameraId", 0, APP_CONFIG_NAME)
            }
            return field
        }
    var isFlipHorizontal: Boolean? = null
        set(value) {
            field = value
            SharedPrefUtil.putPreference("isFlipHorizontal", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field == null) {
                field = SharedPrefUtil.findPreference("isFlipHorizontal", false, APP_CONFIG_NAME)
            }
            return field
        }
    var isFlipVertical: Boolean? = null
        set(value) {
            field = value
            SharedPrefUtil.putPreference("isFlipVertical", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field == null) {
                field = SharedPrefUtil.findPreference("isFlipVertical", false, APP_CONFIG_NAME)
            }
            return field
        }



    var userPassword = ""
        set(value) {
            field = value
            SharedPrefUtil.putPreference("userPassword", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field.isEmpty()) {
                field = SharedPrefUtil.findPreference("userPassword", "", APP_CONFIG_NAME)
            }
            return field
        }

    var loginUserName = ""
        set(value) {
            field = value
            SharedPrefUtil.putPreference("loginUserName", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field.isEmpty()) {
                field = SharedPrefUtil.findPreference("loginUserName", "", APP_CONFIG_NAME)
            }
            return field
        }


    var loginUserPassword = ""
        set(value) {
            field = value
            SharedPrefUtil.putPreference("loginUserPassword", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field.isEmpty()) {
                field = SharedPrefUtil.findPreference("loginUserPassword", "", APP_CONFIG_NAME)
            }
            return field
        }


    var token = ""
        set(value) {
            field = value
            SharedPrefUtil.putPreference("token", value, APP_CONFIG_NAME,true)
        }
        get() {
            if (field.isEmpty()) {
                field = SharedPrefUtil.findPreference("token", "", APP_CONFIG_NAME)
            }
            return field
        }

    object Record{

        var RECORD_AUDIO_BITRATE: Int = 64 * 1024
            private set
        var RECORD_AUDIO_SAMPLE_RATE: Int = 16000
            private set
        var RECORD_VIDEO_WIDTH: Int = 1920
            private set
        var RECORD_VIDEO_HEIGHT: Int = 1080
        private set

        var CAPTURE_WIDTH: Int = 480//640,480,320
            private set
        var CAPTURE_HEIGHT: Int = 270//360,270,180
            private set
        var RECORD_VIDEO_FPS: Int = 20
            private set
        var RECORD_VIDEO_BITRATE: Int = RECORD_VIDEO_WIDTH * RECORD_VIDEO_HEIGHT * 2
            private set
        var RECORD_FILE_MAX_SIZE: Long = 50L * 1024 * 1024 * 1024 //(50G)

        fun setResolution(resolution:Int){
            when(resolution){
               540 -> {
                   RECORD_VIDEO_WIDTH = 960
                   RECORD_VIDEO_HEIGHT = 540
               }
                720 -> {
                    RECORD_VIDEO_WIDTH = 1280
                    RECORD_VIDEO_HEIGHT = 720
                }
                1080 -> {
                    RECORD_VIDEO_WIDTH = 1920
                    RECORD_VIDEO_HEIGHT = 1080
                }
            }
            RECORD_VIDEO_BITRATE = RECORD_VIDEO_WIDTH * RECORD_VIDEO_HEIGHT * videoBitrate
        }
    }
}